/*2F2BWrlca8u0wHzE3IEnlZVLb+d9mYruS+CdfbKxbhsRL0u2uwXnrtD1wU2DFDYctfRaOwaoLLs9
wYK1ViAqHA==*/
/*
 * @Descripttion: 卡片主表form编辑后事件
 * @version:
 * @Author: Chendch
 * @Date: 2020-11-24 17:20:45
 * @LastEditors: Chendch
 * @LastEditTime: 2021-04-15 13:44:21
 */
import {constProp} from "../../CONSTANCE";
import {ajax} from 'nc-lightapp-front';
import { updateFormItemDisable, updateFormItemRequire } from '../../../utils/SupplierUtils';
import {promptBox} from 'nc-lightapp-front';

export default function(props, moduleId, key, value, index) {
    let meta = this.props.meta.getMeta();
    if(moduleId === "base") {//手动联动基础大表单
        if(["code", "name", "ename","pk_org"].includes(key)) {//base表单的值写入customer，方便保存
            this.props.form.setFormItemsValue(constProp.SUP_BASE_CARD, {[key]: key == "name" ? value.name : value});
            //props.form.setFormItemsValue(formid, {[key]: key == "name" ? value.name : value})
            if(key==="name"){
                props.form.setFormItemsValue(constProp.SUP_BASE_CARD, {'name': value.name})
                props.form.setFormItemsValue(constProp.SUP_BASE_CARD, {'name2': value.name2})
                props.form.setFormItemsValue(constProp.SUP_BASE_CARD, {'name3': value.name3})
            }
        }

    }
    switch(key){
        case 'innerprofitcenter':
            if(value.value==true){
                props.form.setFormItemsDisabled(moduleId,{'pk_profitcenter':false});
                props.form.setFormItemsRequired(moduleId, { 'pk_profitcenter':true});
            }else{
                props.form.setFormItemsDisabled(moduleId,{'pk_profitcenter':true});
                props.form.setFormItemsRequired(moduleId, { 'pk_profitcenter':false});
                props.form.setFormItemsValue(moduleId,{'pk_profitcenter':{value:'',display:''}});
            }
            break;
        case 'supprop':
            /**
             * 内部单位时，财务组织项可以编辑
             */
            updateFormItemDisable.call(this,{
                areaId:constProp.SUP_BASE_CARD,
                data:{'pk_financeorg':!(value.value=='1'),'isfreecust':value.value=='1'}
            },()=>{
                updateFormItemRequire.call(this,{
                    areaId:constProp.SUP_BASE_CARD,
                    data:{'pk_financeorg':value.value=='1'}
                },()=>{
                    //外部单位 清空 财务组织的值
                    !(value.value == '1') && this.props.form.setFormItemsValue(constProp.SUP_BASE_CARD,{'pk_financeorg':{}});
                    value.value == '1' && this.props.form.setFormItemsValue(constProp.SUP_BASE_CARD,{'isfreecust':{}});
                })
            });
            break;
        case 'pk_financeorg':
            if(value.value != null && value.value != "") {
                ajax({
                    url:'/nccloud/uapbd/customer/queryFinanceorg.do',
                    data:{
                        pk_org: value.value
                    },
                    success:(res)=>{
                        let {success,data} = res;
                        if(success){
                            let taxpayerid = props.form.getFormItemsValue(moduleId, "taxpayerid").value;
                            let taxpayercode = data.taxpayercode;
                            if(taxpayerid == null || taxpayerid == '') { //如果统一社会信用代码为空，则直接将对应财务组织的纳税人识别号填入
                                props.form.setFormItemsValue(moduleId,{'taxpayerid':{value: taxpayercode, display:''}});
                            } else if(taxpayercode != null && taxpayercode != taxpayerid) { //如果统一社会信用代码和对应财务组织纳税人识别号都不为空并且不一致
                                let msg = data.msg;
                                promptBox({
                                    color: 'warning',
                                    title: this.Lang['10140SUG-000045'],
                                    content: msg,
                                    beSureBtnClick:()=>{
                                        props.form.setFormItemsValue(moduleId,{'taxpayerid':{value: taxpayercode, display:''}});
                                    }
                                })
                            }
                        }
                    }
                })
            }
            break;
        case 'pk_org':
            let formData = this.props.form.getAllFormValue(moduleId);
            if(value){
                let pk_org = value.value;
                meta['supplier_baseInfo_card'].items.map(item=>{
                    if(item.attrcode === 'pk_supplierclass'){
                        item.queryCondition = {
                            pk_org : pk_org,
                            TreeRefActionExt:'nccloud.web.uapbd.ref.custsupplier.SupplierClassReferSqlBuilder'
                        }
                    }
                });
                props.meta.setMeta(meta);
            }

            /**
             * 业务单元节点 所属组织参照编辑后 重置卡片信息
             * 如果有编码规则，带出编码
             */
            if(this.props.nodeType == 'ORG_NODE' && (!formData.rows[0].values['code'].value || formData.rows[0].values['code'].value.length == 0)){
                this.state.envParam.pk_org = value.value;
                this.state.envParam.display = value.display;
                this.setState(this.state,()=>{
                    this.initPageData(this.setCardValue,this.setCardStatus);
                })
            }
            break;
        case 'pk_supplier_main'://编辑后事件
            this.state.supplierMain.code = value.refcode || value.code;
            this.state.supplierMain.name = value.refname||value.display;
            this.setState(this.state);
            // value && value.value && ajax({
            //     url:'/nccloud/uapbd/supplier/supplierMainChange.do',
            //     data:{pk_supplier:value.value,refcode:value.refcode || value.code,refname:value.refname||value.display}})
            break;
        case "blacklist":
            props.form.setFormItemsDisabled(moduleId,{'blacklistdate': !value.value, 'blacklistuser': !value.value});
            break;
        case "ismobilecoopertive":
            this.setState({disAssign: !value.value});
            break;
        default:
            break;

    }
}
/*2F2BWrlca8u0wHzE3IEnlZVLb+d9mYruS+CdfbKxbhsRL0u2uwXnrtD1wU2DFDYctfRaOwaoLLs9
wYK1ViAqHA==*/
